package com.gitee.wsl.jvm.ext

import java.util.Locale

val Locale.code: String
    get() {
        val language = language
        val country = country
        return if (!country.isNullOrEmpty() &&
            (country.equals("tw", ignoreCase = true) ||
                    country.equals("hk", ignoreCase = true))
        ) {
            language.lowercase() + "-" + country.lowercase()
        } else language.lowercase()
    }

val Locale.codeWithCountry: String
    get() {
        val language = language
        val country = country
        return if (!country.isNullOrEmpty()) {
            language.lowercase() + "-" + country.lowercase()
        } else {
            language.lowercase()
        }
    }

// Accepts "Hant" for traditional chinese but no country code otherwise
val Locale.codeForGeonames: String
    get() {
        val language = language
        val country = country
        return if (!country.isNullOrEmpty() &&
            (country.equals("tw", ignoreCase = true) ||
                    country.equals("hk", ignoreCase = true))
        ) {
            language.lowercase() + "-Hant"
        } else {
            language.lowercase()
        }
    }

// Everything in uppercase + "ZHT" for traditional Chinese
val Locale.codeForNaturalEarthService: String
    get() {
        val language = language
        val country = country
        return if (!country.isNullOrEmpty() &&
            (country.equals("tw", ignoreCase = true) ||
                    country.equals("hk", ignoreCase = true))
        ) {
            language.uppercase() + "T"
        } else language.uppercase()
    }

val Locale.isChinese: Boolean
    get() = code.startsWith("zh")

val Locale.isIndian: Boolean
    get() = code.startsWith("hi") || code.startsWith("mr")
